import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_taotaoshipin/common/theme/dimens.dart';
import 'package:flutter_taotaoshipin/util/theme_utils.dart';
import 'package:flutter_taotaoshipin/widget/gaps.dart';
import 'package:flutter_taotaoshipin/widget/load_image.dart';

class StateView extends StatelessWidget {
  const StateView({
    super.key,
    required this.type,
    this.hintText,
  });

  final StateType type;
  final String? hintText;

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        if (type == StateType.loading)
          const CupertinoActivityIndicator(radius: 16)
        else if (type != StateType.empty)
          Opacity(
            opacity: context.isDark ? 0.5 : 1,
            child: LoadAssetImage(
              'state/${type.img}',
              width: 120,
            ),
          ),
        const SizedBox(
          width: double.infinity,
          height: Dimens.gap_dp16,
        ),
        Text(
          hintText ?? type.hintText,
          style: Theme.of(context)
              .textTheme
              .titleSmall
              ?.copyWith(fontSize: Dimens.font_sp14),
        ),
        Gaps.vGap50,
      ],
    );
  }
}

enum StateType {
  /// 主剧
  drama,

  /// 观看历史
  watchHistory,

  /// 充值记录
  purchase,

  /// 无网络
  network,

  /// 加载中
  loading,

  /// 空
  empty
}

extension StateTypeExt on StateType {
  String get img => <String>['zwzj', 'zwjl', 'zwjl', 'zwwl', '', ''][index];

  String get hintText =>
      <String>['敬请期待', '暂无观看记录', '暂无充值记录', '无网络连接', '', ''][index];
}
